#   Copyright (C) 2008      Tri Tech Information Systems Inc.
# 
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
# 
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
# 
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#   
from pyxx.wrapper import ExposedWrapper
from pyxx.formatters import *

class EnumWrapper( ExposedWrapper ):
    WRAPPER_TEMPLATE = '''
       %(enum_type)s< %(qualifiedName)s >(%(args)s)
                %(values)s
                ;
    '''

    def generate_wrapper_bases(self):
        return ""

    def __init__(self, ctx, enum, module, remove_prefix = None, exported = False, **kw):
        ExposedWrapper.__init__(self, ctx, enum, **kw)
        self.module = module           
        self.remove_prefix = remove_prefix
        self.exported = exported

    def generate_enum_type(self):
        if self.exported:
            return "exported_enum_"
        else:
            return "enum_"

    @formatter(list)
    def generate_values(self):
        for enum in self.item.enumerators:
            parts = '::' + '::'.join(list(self.scope) + [enum.name])
            name = enum.name
            if self.remove_prefix:
                name = name[len(self.remove_prefix):]
            yield  '.value( "%s", %s)' % (name, parts)

    @generator        
    @formatter( argument_list )
    def generate_args( self ):
        if not self.exported:
            prefix = None
        else:
            if self.remove_prefix:
                prefix = '"%s"' % self.remove_prefix
            else:
                prefix = '""'
        return ["%(quoted_python_name)s", prefix]
                

